import {PlusOutlined} from '@ant-design/icons';
import type {ActionType, ProColumns, ProDescriptionsItemProps} from '@ant-design/pro-components';
import {
    FooterToolbar,
    ModalForm,
    PageContainer,
    ProDescriptions, ProFormCheckbox,
    ProFormText,
    ProFormTextArea,
    ProTable,
    ProForm,
    ProFormDateRangePicker, ProFormDigit, ProFormUploadButton, ProFormSelect, ProFormDateTimePicker,
} from '@ant-design/pro-components';
import {
    Button,
    Drawer,
    Input,
    message,
    Modal,
    Tag,
    Badge,
    Space,
    Statistic,
    DatePicker,
    Descriptions,
    Divider, Card, notification
} from 'antd';
import React, {useRef, useState, useEffect} from 'react';
import type {LicenseListItem} from './data';
import {licenseMy, licenseImport} from './service';

const {confirm} = Modal;
/**
 * 添加节点
 *
 * @param fields
 */

/**
 * 更新节点
 *
 * @param fields
 */

export type FormValueType = {
    target?: string;
    template?: string;
    type?: string;
    time?: string;
    frequency?: string;
} & Partial<LicenseListItem>;


/**
 * 删除节点
 *
 * @param selectedRows
 */

const LicenseList: React.FC = () => {
    const [componentDisabledVisible, setComponentDisabledVisible] = useState<boolean>(true);
    const [licenseData, setLicenseData] = useState<LicenseListItem>();
    const [loading, setLoading] = useState(true);

    // useEffect(() => {
    //     // 从接口获取数据
    //     let data = fetchOptionsResource();
    //     setLicenseData(data );
    //     setLoading(false);
    // }, []);

    useEffect(() => {
        const fetchLicenseData = async () => {
            try {
                const response = await licenseMy({});
                setLicenseData(response.data);
            } catch (error) {
                console.error('Error fetching form data:', error);
            } finally {
                setLoading(false);
            }
        };
        fetchLicenseData();
    }, []);
    // const { data: optionsResource, run: fetchOptionsResource } = useRequest(
    //     async () => {
    //         const res = await licenseMy({});
    //         return res.data;
    //     }
    // );
    // const fetchLicenseData = async () => {
    //     const response = await licenseMy({})
    //     setLicenseData(response.data);
    //     setLoading(false);
    // };
    /** 国际化配置 */
    return (
        <PageContainer
        >
            <Card
                style={{
                    marginBottom: 32,
                }}
            >
                {!loading && (
                    <ProForm
                        submitter={{
                            // 配置提交按钮
                            submitButtonProps: false,
                            // 禁用重置按钮
                            resetButtonProps: false,
                            // 自定义其他按钮
                            render: (_, dom) => [
                                <div
                                    style={{
                                        display: 'flex',
                                        justifyContent: 'flex-end',
                                        marginTop: '16px',
                                        gap: '16px'
                                    }}
                                >
                                    {componentDisabledVisible && (
                                        <Button
                                            type="primary"
                                            onClick={() => {
                                                setComponentDisabledVisible(false)
                                            }}
                                        >
                                            编辑
                                        </Button>
                                    )}
                                    {!componentDisabledVisible && (
                                        <Button
                                            type="primary"
                                            onClick={() => {
                                                setComponentDisabledVisible(true)
                                            }}
                                        >
                                            取消
                                        </Button>
                                    )}
                                    {!componentDisabledVisible && (
                                        <Button type="primary">导入</Button>
                                    )}
                                </div>,
                            ],
                        }}
                        initialValues={{license: licenseData?.license}}
                    >
                        <ProFormTextArea
                            // width="md"
                            name="license"
                            label=""
                            fieldProps={{
                                rows: 4, // 设置文本域高度为 4 行
                            }}
                            disabled={componentDisabledVisible}
                        />
                    </ProForm>
                )}
            </Card>

            <Card bordered={false}>
                <Descriptions
                    title="LICENSE解析"
                    style={{
                        marginBottom: 32,
                    }}
                >
                    <Descriptions.Item label="组织名称">{licenseData?.organizationName}</Descriptions.Item>
                    <Descriptions.Item label="邮箱地址">{licenseData?.email}</Descriptions.Item>
                    <Descriptions.Item label="系统版本">{licenseData?.systemVersion}</Descriptions.Item>
                    <Descriptions.Item label="最大用户数">{licenseData?.userLimit}</Descriptions.Item>
                    <Descriptions.Item label="最大资源数">{licenseData?.resourceLimit}</Descriptions.Item>
                    <Descriptions.Item label="导入时间">{licenseData?.createdAt}</Descriptions.Item>
                    <Descriptions.Item label="有效期至">{licenseData?.expireAt}</Descriptions.Item>
                </Descriptions>
                <Divider
                    style={{
                        marginBottom: 32,
                    }}
                />
            </Card>

        </PageContainer>
    );
};

export default LicenseList;
